//
//  YDOrigionView.swift
//  weibo
//
//  Created by 孙亚东 on 16/6/27.
//  Copyright © 2016年 Sunyadong. All rights reserved.
//

import UIKit
import SDWebImage



class YDOrigionView: UIView {

    let margin: CGFloat = 10.0;
    
    //设置一个viewModel的属性,重写set方法
    var userViewModel: YDUserViewModel? {
        
        didSet{
            
            headerImage.sd_setImageWithURL(userViewModel?.photoUrl)
            screen_name.text = userViewModel?.name
            levelImg.image = userViewModel?.levelImage
            markImage.image = userViewModel?.verifyImage
            contentLab.text = userViewModel?.content
            
            
            // 传过去的应该是一个viewModel,里面放着模型数组
            pictureView.picturesViewModels = userViewModel?.model?.pic_urls
            
      
        }
        
    }

    
    override init(frame: CGRect) {
        
        super.init(frame: frame)
        
        
        
        setupUI()
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    
    
    //添加控件设置约束
    
    func setupUI () {

        
        addSubview(headerImage)
        addSubview(screen_name)
        addSubview(levelImg)
        addSubview(timeLab)
        addSubview(sourceLab)
        addSubview(markImage)
        addSubview(pictureView)
        addSubview(contentLab)
        
        //设置约束
        headerImage.snp_makeConstraints { (make) -> Void in
            
            make.left.top.equalTo(self).offset(margin)
            make.width.equalTo(40)
            make.height.equalTo(40)
     
            
        }
        
        screen_name.snp_makeConstraints { (make) -> Void in
            
            make.left.equalTo(headerImage.snp_right).offset(margin)
            make.top.equalTo(headerImage)
            
            
            
        }
        
        levelImg.snp_makeConstraints { (make) -> Void in
            
            make.left.equalTo(screen_name.snp_right).offset(margin)
            make.centerY.equalTo(screen_name)
            
            
        }
        
        
        timeLab.snp_makeConstraints { (make) -> Void in
            
            make.bottom.equalTo(headerImage)
            make.left.equalTo(headerImage.snp_right).offset(margin)
      
            
        }
        
        sourceLab.snp_makeConstraints { (make) -> Void in
            
            make.left.equalTo(timeLab.snp_right).offset(margin)
            make.bottom.equalTo(headerImage)
            
            
        }
        
        markImage.snp_makeConstraints { (make) -> Void in
            
            make.centerX.equalTo(headerImage.snp_right)
            make.centerY.equalTo(headerImage.snp_bottom)
            
            
        }
        
        contentLab.snp_makeConstraints { (make) -> Void in
            
            make.left.equalTo(self).offset(margin)
            
            make.top.equalTo(headerImage.snp_bottom).offset(margin)

            make.width.equalTo(screenWidth-margin-margin)
            
            make.bottom.equalTo(pictureView.snp_top).offset(-10)
        
        }
        //设置pictureView的frame
        
        pictureView.snp_makeConstraints { (make) -> Void in
            
            make.left.equalTo(self.snp_left).offset(10)
            make.right.equalTo(self).offset(-10)
            

        }
        
        self.snp_makeConstraints { (make) -> Void in
            
            
            make.bottom.equalTo(pictureView)
            
            
        }
        

    }
    
    
    
    
    //懒加载控件
    
    lazy var headerImage: UIImageView = {
    
        let headerImg = UIImageView()
        
        return headerImg
    
    
    }()
    
    lazy var screen_name: UILabel = {
    
        let lab = UILabel()
        
        return lab
    
    }()
    
    lazy var levelImg: UIImageView = {
    
        let levelImg = UIImageView()
        
        return levelImg
    
    
    }()
    
    
    lazy var timeLab: UILabel = {
    
    
        let timeLab = UILabel()
        
        timeLab.text = "时间"
        
        timeLab.font = UIFont.systemFontOfSize(13.0)
        
        
        return timeLab
    
    
    }()
    
    lazy var sourceLab: UILabel = {
    
        let sourceLab = UILabel()
        
        sourceLab.font = UIFont.systemFontOfSize(13.0)
        
        sourceLab.text = "来源"
        
        return sourceLab
    
    }()
    
    
    lazy var markImage: UIImageView = {
    
        let markImg = UIImageView()
        
        return markImg
    
    
    
    }()
    
    
    lazy var contentLab: UILabel = {
    
        let contentLab = UILabel()
        
        contentLab.numberOfLines = 0
        
        contentLab.font = UIFont.systemFontOfSize(13.0)
        
        return contentLab
    
    
    
    }()
    
    //懒加载PictureView
    lazy var pictureView: YDPictureView = YDPictureView()
    
    
    
    
    
}
